package com.api.oa.services.impl;

import cn.hutool.core.date.DateUtil;
import com.api.oa.mapper.YQCheckPatientMapper;
import com.api.oa.model.entity.YQCheckPatient;
import com.api.oa.services.YQCheckPatientService;
import com.api.oa.utils.LocalRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;


@Service
public class YQCheckPatientServiceImpl implements YQCheckPatientService {

    @Autowired
    private YQCheckPatientMapper mapper;
    @Autowired
    private LocalRedis localRedis;
    


    @Override
    public Integer add(YQCheckPatient entity) {
        entity.setCreatedAt(DateUtil.date());
        return mapper.insert(entity);
    }

    @Override
    public void remove(Long id) {
        mapper.delete(id);
    }

    @Override
    public Integer update(YQCheckPatient entity) {
        return mapper.update(entity);
    }

    @Override
    public PageInfo<YQCheckPatient> list(Long pid,Integer pageIndex,Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        PageHelper.orderBy("createdAt desc");
        return new PageInfo<>(mapper.list(pid));
    }

    @Override
    public YQCheckPatient one(Long id) {
     return mapper.findOne(id);
    }

    
    @Override
    public List<YQCheckPatient> all() {
        Object o = localRedis.get("YQCheckPatientService.all");
        if(o == null){
            List<YQCheckPatient> all = mapper.all();
            localRedis.set("YQCheckPatientService.all",all,3600*24);
            return all;
        }
        return (List<YQCheckPatient>) o;
    }


}
